package com.example.villagemarket;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class ShoppingCart {

	// The hashmap will contain all of the items in the shopping cart
	// The key will be the item name, and the value is an array list
	// that will contain the quantity and price
	public static HashMap<String, ArrayList<String>> items = new HashMap<String, ArrayList<String>>();

	TextView badgeCount;
	LayoutInflater inflater;
	View v;
	
	static Menu menu;


	public void updateCart(Context context, Activity activity, Menu m) {

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		v = inflater.inflate(R.layout.shopping_cart_notification, null);
		
		 badgeCount = (TextView)m.findItem(R.id.shoppingCart).getActionView().findViewById(R.id.actionbar_notifcation_textview);
		 if(items.size() > 0)
		 {
			 badgeCount.setVisibility(View.VISIBLE);
				
				badgeCount.setText(" " + items.size() + " ");
		 }
		 else
		 {
			 badgeCount.setVisibility(View.INVISIBLE);
				
				badgeCount.setText(" " + 0 + " ");
		 }

		
		
	}

	public static BigDecimal getTotal() {
		
		BigDecimal toReturn = new BigDecimal(0);
		
		for (Map.Entry<String, ArrayList<String>> entry : items.entrySet()) {
		    ArrayList<String> value = entry.getValue();
		    
		   
		    BigDecimal amount = new BigDecimal(value.get(0));
		    BigDecimal price = new BigDecimal(value.get(1));
		    
		    BigDecimal temp = amount.multiply(price);
		    toReturn = toReturn.add(temp);
		    


		}
		
		return toReturn;
	}
	
	public static void retainMenu(Menu m)
	{
		menu = m;
	}

}
